package com.ksd.reustb;

import lombok.Data;

import java.io.Serializable;

@Data
public class Result<T> implements Serializable {

    private Result(){}

    private Boolean success;

    private Integer code;

    private String  message;

    private T data;


    public static Result<String> ok(){
        Result<String> result = new Result<>();
        result.setSuccess(true);
        result.setCode(ResultCode.SUCCESS);
        result.setMessage(ResultMessage.SUCCESS);
        result.setData("");
        return result;
    }

    public static<T> Result<T> ok(T data){
        Result<T> result = new Result<>();
        result.setSuccess(true);
        result.setCode(ResultCode.SUCCESS);
        result.setMessage(ResultMessage.SUCCESS);
        result.setData(data);
        return result;
    }

    public static Result<String> ok(Integer resultCode,String resultMessage){
        Result<String> result = new Result<>();
        result.setSuccess(true);
        result.setCode(resultCode);
        result.setMessage(resultMessage);
        result.setData("");
        return result;
    }

    public static<T> Result<T> ok(Integer resultCode,String resultMessage,T data){
        Result<T> result = new Result<>();
        result.setSuccess(true);
        result.setCode(resultCode);
        result.setMessage(resultMessage);
        result.setData(data);
        return result;
    }




    public static Result<String> fail(){
        Result<String> result = new Result<>();
        result.setSuccess(true);
        result.setCode(ResultCode.ERROR);
        result.setMessage(ResultMessage.ERROR);
        result.setData("");
        return result;
    }

    public static<T> Result<T> fail(T data){
        Result<T> result = new Result<>();
        result.setSuccess(true);
        result.setCode(ResultCode.ERROR);
        result.setMessage(ResultMessage.ERROR);
        result.setData(data);
        return result;
    }

    public static Result<String> fail(Integer resultCode,String resultMessage){
        Result<String> result = new Result<>();
        result.setSuccess(true);
        result.setCode(resultCode);
        result.setMessage(resultMessage);
        result.setData("");
        return result;
    }

    public static<T> Result<T> fail(Integer resultCode,String resultMessage,T data){
        Result<T> result = new Result<>();
        result.setSuccess(true);
        result.setCode(resultCode);
        result.setMessage(resultMessage);
        result.setData(data);
        return result;
    }


}
